<template>
    <div id="feedback">
        <el-col :span="24" class="toolbar" style="padding-bottom: 0;">
            <el-form :inline="true" :model="ActData">
                <el-form-item>
                    <el-input type="number" min="0" v-model="ActData.id" placeholder="请输入要搜索的ID"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-input v-model="ActData.body" placeholder="请输入要搜索的内容"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="postFeedback">查询</el-button>
                </el-form-item>
            </el-form>
        </el-col>
        <el-table :data="ActIty" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column prop="id" label="ID" width="80"></el-table-column>
            <el-table-column prop="body" label="内容(点击查看详情)">
                <template slot-scope="scope">
                    <div @click="detailsDit(scope.row)">
                        <p class="text">{{scope.row.body}}</p>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="发布时间">
                <template slot-scope="scope">
                    <p v-if="scope.row.createDateString">{{scope.row.createDateString | formatDate}}</p>
                    <p v-else>暂无时间</p>
                </template>
            </el-table-column>
            <el-table-column label="用户名(昵称)">
                <template slot-scope="scope">
                    <p>{{scope.row.user.username}}({{scope.row.user.nickName}})</p>
                </template>
            </el-table-column>
            <el-table-column label="操作" width="150">
                <template slot-scope="scope">
                    <el-button type="danger" size="small" @click="handleDel(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <!--分页-->
        <el-col :span="24" class="toolbar">
            <el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="size"
                           :total="total" style="float:right;"></el-pagination>
        </el-col>
        <!--说说详情-->
        <el-dialog title="说说详情" :visible.sync="dialogVisible" :before-close="handleClose">
            <span v-if="detailsDialog" v-text="detailsDialog"></span>
            <span v-else>没有数据</span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">返   回</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
    import util from '../../common/js/util';
    import {feedbackList,feedbackDel} from '../../api/api';
    import {formatDate} from '../../common/js/formatDate';
    export default {
        data() {
            return {
                ActIty: [],
                total: 0,
                page: 1,
                size: 10,
                ActData: {
                    id: null,
                    body: ''
                },
                listLoading: false,
                fall: '',
                dialogVisible: false,
                detailsDialog : '',
            }
        },
        methods: {
            selsChange: function (sels) {
                this.sels = sels;
            },
            handleCurrentChange(val) {
                this.page = val;
                this.postFeedback();
            },
            postFeedback(){
                let para = {
                    page: this.page,
                    size: this.size,
                    data: this.ActData
                };
                feedbackList(para).then(res => {
                    this.ActIty = res.data.content;
                    this.total = res.data.totalElements;
                })
            },

            /*删除*/
            handleDel(row){
                this.listLoading = true;
                feedbackDel(row.id).then(res => {
                    console.log(res);
                    this.listLoading = false;
                    this.$message({
                        message: res.message,
                        type: 'success'
                    });
                    this.postFeedback();
                })
            },
            detailsDit(row){
                this.dialogVisible = true;
                this.detailsDialog = row.body;
            },
            handleClose(done){done();},
        },
        mounted(){
            this.postFeedback();
        },
        filters: {
            formatDate(time) {
                let date = new Date(time);
                return formatDate(date, 'yyyy-MM-dd');
            }
        },
    }
</script>
<style type="text/scss" lang="scss" scoped>
    #feedback{
        .text{
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            cursor: pointer;
        }
    }
</style>